<template>
  <j-modal
    :title="title"
    :visible="visible"
    @cancel="handleCancel"
    width="850px"
    :confirmLoading="confirmLoading"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel" :disabled="confirmLoading">{{ $t('关闭') }}</a-button>
      <a-button type="primary" v-if="!disableSubmit" @click="handleOk" :disabled="confirmLoading">{{ $t('确定') }}</a-button>
    </template>
    <div style="margin-left: 10px">
      <j-form-container :disabled="disableSubmit">
        <a-form-model
          :rules="rules"
          :model="dataForm"
          ref="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-enterToNext
          slot="detail"
        >
          <a-row>
            <div style="margin: 0 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('基本信息') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" prop="code" :label="$t('项目编码')">
                <a-input v-model="dataForm.code"></a-input>
              </a-form-model-item>
              <a-form-model-item style="margin-bottom: 10px" :label="$t('项目分类')" prop="typeId">
                <div style="display:flex;align-items:center;">
                  <a-tree-select
                    allowClear
                    v-model="dataForm.typeId"
                    :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
                    :tree-data="sortList"
                    :placeholder="$t('请选择')"
                  />
                  <a v-has="'BisGameTypeController:add'" @click="handleAddType"><a-icon type="plus" style="margin: 0 2px" /></a>
                  <a v-has="'BisGameTypeController:edit'" v-if="dataForm.typeId"><a-icon type="edit" style="margin: 0 2px" @click="handleEditType" /></a>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" prop="name" :label="$t('项目名称')">
                <a-input v-model="dataForm.name"></a-input>
              </a-form-model-item>
              <a-form-model-item style="margin-bottom: 10px" :label="$t('消费方式')" prop="consumeType">
                <a-select
                  :placeholder="$t('请选择')"
                  :disabled="consumeTypeDisabled"
                  v-model="dataForm.consumeType"
                  @change="handleChangepaytype"
                >
                  <a-select-option
                    v-for="(item, i) in stateList"
                    :key="i"
                    :value="item.value"
                    :disabled="item.disabled"
                    >{{ item.title }}</a-select-option
                  >
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 19 }"
                prop="comment"
                style="margin-bottom: 10px"
                :label="$t('备注')"
              >
                <a-input v-model="dataForm.comment"></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="consumeTypeState == 3">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('应用参数') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币类型')" prop="inputType">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.inputType"
                  dictCode="bis_game.input_type"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('每小时扣币')" prop="hourCoin">
                <a-input v-model="dataForm.hourCoin"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币间隔（秒）')" prop="inputInterval">
                <a-input v-model="dataForm.inputInterval"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 20 }"
                :label="$t('计费周期')"
              >
                <i18n path="cycle" tag="span">
                  <a-input
                    place="hour"
                    oninput="value=value.replace(/\D/g,'');"
                    v-model="dataForm.hourTime"
                    style="width: 60px"
                  ></a-input>
                  <a-input
                    place="time"
                    oninput="value=value.replace(/\D/g,'');"
                    v-model="dataForm.cycleTime"
                    style="width: 60px"
                  ></a-input>
                </i18n>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 18 }"
                :label="$t('进门押金')"
                prop="deposit"
              >
                <div>
                  <a-input v-model="dataForm.deposit" style="width: 100px"></a-input
                  ><span style="padding: 0 4px">{{ $t('币') }}</span
                  ><span style="color: orange">{{ $t('(进门时需一次性扣除的费用，出门结算时多退少补)') }}</span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 18 }"
                :label="$t('后悔时间')"
                prop="freeTime"
              >
                <div>
                  <a-input v-model="dataForm.freeTime" style="width: 100px"></a-input
                  ><span style="padding: 0 4px">{{ $t('分钟') }}</span
                  ><span style="color: orange">{{ $t('(进门后消费时长不足该时长时不收取费用)') }}</span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 18 }"
                :label="$t('最低消费')"
                prop="minCoin"
              >
                <div>
                  <a-input v-model="dataForm.minCoin" style="width: 100px"></a-input
                  ><span style="padding: 0 4px">{{ $t('币') }}</span
                  ><span style="color: orange">{{ $t('(结算时若本次消费币值不足该值则按最低消费值扣费)') }}</span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 18 }"
                :label="$t('最高消费')"
                prop="maxCoin"
              >
                <div>
                  <a-input v-model="dataForm.maxCoin" style="width: 100px"></a-input
                  ><span style="padding: 0 4px">{{ $t('币') }}</span
                  ><span style="color: orange">{{ $t('(结算时若本次消费币值超过该值则按最高消费值扣费)') }}</span>
                </div>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="consumeTypeState == 2">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('应用参数') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币类型')" prop="inputType">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.inputType"
                  dictCode="bis_game.input_type"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('一局扣币')" prop="onceCoin1">
                <a-input v-model="dataForm.onceCoin1"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('一局脉冲')" prop="oncePulse">
                <a-input v-model="dataForm.oncePulse"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币间隔（秒）')" prop="inputInterval">
                <a-input v-model="dataForm.inputInterval"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 19 }"
                style="margin-bottom: 10px"
                :label="$t('绑定门票')"
              >
                <a-select
                  showSearch
                  :value="piaoValue"
                  :placeholder="$t('请输入编码/名称/条码')"
                  style="width: 270px"
                  :defaultActiveFirstOption="false"
                  :showArrow="false"
                  :filterOption="false"
                  @search="handleSearch"
                  @change="handleChange"
                >
                  <a-select-option v-for="d in piaoList" :key="d.id">{{ d.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="16" :offset="4">
              <a-table :columns="columns" :dataSource="dataSource" :pagination="false" bordered>
                <template slot="action" slot-scope="text, record, i">
                  <a-icon type="close" @click="deleteGoods(text, record, i)" />
                </template>
              </a-table>
            </a-col>
            <a-col :span="5" :offset="1">
              <a-form-model-item
                style="margin: 10px 0px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 20 }"
                prop="allowPlay"
              >
                <a-checkbox v-model="dataForm.allowPlays">{{ $t('限制可玩次数') }}</a-checkbox>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item
                style="margin: 10px 0px"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 16 }"
                :label="$t('可玩次数')"
              >
                <a-input-number v-model="dataForm.playTimes" :min="0" style="width: 50%"></a-input-number>
                <span style="margin-left: 10px; color: orange">{{ $t('（0表示不限次）') }}</span>
              </a-form-model-item>
            </a-col>
            <a-col :span="23" :offset="1">
              <a-form-model-item style="margin-bottom: 10px">
                <a-checkbox v-model="dataForm.checkPicture">{{ $t('年月票验证照片') }}</a-checkbox>
                <span style="margin-left: 10px; color: orange">{{ $t('（开启后验票机上扣年月票时需要验证照片）') }}</span>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="consumeTypeState == 2">
            <div style="margin: 0 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('其它') }}
              <a-button style="margin-left: 20px" type="link" @click="addPrice">{{ $t('添加') }}</a-button>
            </div>
            <a-col :span="24" v-for="(ele, i) in priceList" :key="i">
              <a-row>
                <a-col :span="10">
                  <a-form-model-item :label="$t('一局扣币')">
                    <a-input v-model="ele.price"></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item :label="$t('会员类型')">
                    <a-select v-model="ele.memberTypeId" :placeholder="$t('请选择会员类型')">
                      <a-select-option v-for="(l, ind) in memberTypeList" :key="ind" :value="l.id">{{
                        l.name
                      }}</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
                <a-col :span="4">
                  <a-button style="float: right" type="link" @click="delPrice(i)">{{ $t('删除') }}</a-button>
                </a-col>
                <a-col :span="20">
                  <a-form-model-item :label="$t('有效日')" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
                    <a-checkbox-group v-model="ele.weeks" style="margin-top: 6px; margin-left: 5px">
                      <a-checkbox style="margin-left: 8px" :value="item.key" v-for="item in weeks" :key="item.key">{{
                        item.name
                      }}</a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
                <a-col :span="20">
                  <a-form-model-item :label="$t('有效时段')" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
                    <template v-for="(vTime, index) in ele.periodList">
                      <a-tag :key="index" closable @close="() => delValidTime(index, i)" class="tag-active">
                        {{ vTime.beginTime + '~' + vTime.endTime }}
                      </a-tag>
                    </template>
                    <a-button type="link" @click="addValidTime(i)" v-if="!ele.isAdd">{{ $t('添加') }}</a-button>
                    <span v-else style="padding-left: 6px">
                      <a-time-picker
                        v-model="ele.beginTime"
                        :placeholder="$t('开始时间')"
                        format="HH:mm"
                        style="width: 120px"
                        @openChange="(b) => focusTimeE(b, i)"
                      />~
                      <a-time-picker
                        v-model="ele.endTime"
                        :placeholder="$t('结束时间')"
                        format="HH:mm"
                        style="width: 120px"
                        @openChange="(b) => orgTime(b, i)"
                      />
                    </span>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-col>
          </a-row>
          <a-row v-if="consumeTypeState == 1">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('投币参数') }}
            </div>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 14px"
                :label="$t('投币类型')"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 20 }"
                required
              >
                <div>
                  <div>
                    <a-button type="link" @click="addInputType">{{ $t('添加') }}</a-button>
                    <span style="color: orange; padding-left: 10px">{{
                      $t('说明：投币优先级按表格从上到下执行。')
                    }}</span>
                  </div>
                  <a-table
                    ref="table"
                    size="middle"
                    class="j-table-force-nowrap cus-table1"
                    bordered
                    :columns="inputColumns"
                    :dataSource="inputDataSource"
                    :pagination="false"
                    style="width:620px"
                  >
                    <span slot="action" slot-scope="text, record, index">
                      <a>
                        <a-icon type="arrow-up" @click="handleUp(index)" style="margin-right: 4px" v-if="index != 0" />
                        <a-icon
                          type="arrow-down"
                          style="margin-right: 4px"
                          @click="handleDown(index)"
                          v-if="index != inputDataSource.length - 1"
                        />
                        <a-icon type="close" @click="handleDelete(index)" />
                      </a>
                    </span>
                  </a-table>
                </div>
                <!-- <div style="display: flex">
                  <a-form-model-item
                    style="margin-bottom: 10px; width: 140px"
                    :labelCol="{ span: 0 }"
                    :wrapperCol="{ span: 24 }"
                    prop="inputMode"
                  >
                    <j-dict-select-tag
                      :placeholder="$t('请选择')"
                      v-model="dataForm.inputMode"
                      dictCode="bis_game.input_mode"
                      @change="changeInputMode"
                    />
                  </a-form-model-item>
                  <a-form-model-item
                    style="margin-bottom: 10px; width: 180px; margin-left: 4px"
                    :labelCol="{ span: 0 }"
                    :wrapperCol="{ span: 24 }"
                    prop="inputType"
                  >
                    <j-dict-select-tag
                      :placeholder="$t('请选择')"
                      v-model="dataForm.inputType"
                      dictCode="bis_game.input_type"
                      v-if="dataForm.inputMode == 0"
                    />
                    <a v-if="dataForm.inputMode == 1" @click="addInputType">
                      {{ inputType_dictText }}
                      <a-icon type="plus" v-if="inputType_dictText == ''" />
                    </a>
                  </a-form-model-item>
                </div> -->
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币速度')" prop="inputSpeed">
                <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.inputSpeed" dictCode="bis_game.speed" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币脉宽')" prop="inputWidth">
                <a-input v-model="dataForm.inputWidth"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币极性')" prop="inputPolarity">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.inputPolarity"
                  dictCode="bis_game.polarity"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投实币模式')" prop="allowIncurrency">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.allowIncurrency"
                  dictCode="bis_game.allow_incurrency"
                />
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('一局金额')" prop="onceAmount">
                <a-input v-model="dataForm.onceAmount"></a-input>
              </a-form-model-item>
            </a-col> -->
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('一局扣币')" prop="onceCoin1">
                <a-input v-model="dataForm.onceCoin1"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="dataForm.allowIncurrency==2">
              <a-form-model-item style="margin-bottom: 10px" prop="currencyPulse">
                <span slot="label">
                  {{ $t('实币脉冲') }}
                  <a-tooltip :title="$t('投一个实币机台上的脉冲数')">
                    <a-icon type="question-circle-o" />
                  </a-tooltip>
                </span>
                <a-input-number
                  style="width: auto;"
                  ref="currencyPulse"
                  v-model="dataForm.currencyPulse"
                  :min="1"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('一局脉冲')" prop="oncePulse">
                <a-input v-model="dataForm.oncePulse"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="dataForm.inputByCardSoon == 1">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('游戏局数')" prop="playTimes">
                <a-input-number v-model="dataForm.playTimes" :min="1" style="width: 100%"></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('检查投币线')" prop="checkInputLine">
                <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.checkInputLine" dictCode="yn" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币间隔（秒）')" prop="inputInterval">
                <a-input v-model="dataForm.inputInterval"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投币档位模式')" prop="inputByCardSoon">
                <a-select v-model="dataForm.inputByCardSoon">
                  <a-select-option :value="1">{{ $t('固定档位') }}</a-select-option>
                  <a-select-option :value="0">{{ $t('可选档位') }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="dataForm.inputByCardSoon != 1">
              <a-form-model-item
                style="margin-bottom: 10px"
                :label="$t('投币档位')"
                prop="inputGear"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 20 }"
              >
                <div>
                  <div>
                    <span v-for="(gear, i) in inputGears" :key="i">
                      <a-input
                        v-model="gear.value"
                        style="width: 73px; padding: 0 4px"
                        oninput="if(value >20000) value = 20000"
                      />
                      <a-button type="link" icon="close" @click="delGear(gear, i)"></a-button>
                    </span>
                    <a-button type="link" @click="addGear">{{ $t('添加') }}</a-button>
                  </div>
                  <div style="line-height: 1">
                    <span style="color: #df611c">{{ $t('（投币档位位值必须为一局扣币值的整数倍）') }}</span>
                  </div>
                </div>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="consumeTypeState == 1">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('退票参数') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票类型')" prop="outputType">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.outputType"
                  dictCode="bis_game.output_type"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票速度')" prop="outputSpeed">
                <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.outputSpeed" dictCode="bis_game.speed" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票脉宽')" prop="outputWidth">
                <a-input v-model="dataForm.outputWidth"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票极性')" prop="outputPolarity">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.outputPolarity"
                  dictCode="bis_game.polarity"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="dataForm.outputType != 4 && dataForm.outputType != 0">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票倍率')" prop="outputRatio">
                <a-input v-model="dataForm.outputRatio"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="dataForm.outputType == 4">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('绑定商品')" prop="outputGoodsId">
                <a-select
                  v-model="dataForm.outputGoodsId"
                  show-search
                  :placeholder="$t('请输入商品编码/名称/条码')"
                  :filter-option="false"
                  :not-found-content="null"
                  @search="handleGoodsSearch"
                >
                  <a-select-option v-for="good in addGoodsList" :key="good.id">{{ good.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退实票')" prop="outputCoin">
                <a-select v-model="dataForm.outputCoin" :placeholder="$t('请选择')">
                  <a-select-option :value="item.value" :key="index" v-for="(item, index) in outputCoinList">
                    <span v-if="item.value == 5">
                      {{ item.title }}
                      <a-tooltip :title="$t('退票直接出实票，卡头计数，不支持存卡')">
                        <a-icon type="question-circle" style="margin-left: 3px" />
                      </a-tooltip>
                    </span>
                    <span v-else-if="item.value == 6">
                      {{ item.title }}
                      <a-tooltip :title="$t('会员扫码/刷卡投币，退票后存入会员账户；投实币退实票')">
                        <a-icon type="question-circle" style="margin-left: 3px" />
                      </a-tooltip>
                    </span>
                    <span v-else>{{ item.title }}</span>
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('最大退票额度')" prop="maxOutputValue">
                <a-input-number
                  v-model="dataForm.maxOutputValue"
                  :precision="0"
                  style="width: 100%"
                  :min="1"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票时SSR延迟')" prop="outputLotterySsrDelay">
                <a-input
                  v-model="dataForm.outputLotterySsrDelay"
                  oninput="value=value.replace(/\D/g,'');if(value>60)value=60;"
                ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('支持卡头退票键')" prop="machineOutputLottery">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.machineOutputLottery"
                  dictCode="bis_game.machine_output_lottery"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item
                style="margin-bottom: 10px"
                :label="$t('退票键输出时长')"
                prop="outputLotteryKeyboardTime"
              >
                <a-input v-model="dataForm.outputLotteryKeyboardTime" oninput="value=value.replace(/\D/g,'');"></a-input>
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退票延迟')" prop="outputLotteryDelay">
                <a-input
                  v-model="dataForm.outputLotteryDelay"
                  :maxLength="2"
                  oninput="value=value.replace(/\D/g,'');if(value>60)value=60;"
                ></a-input>
              </a-form-model-item>
            </a-col> -->
          </a-row>
          <a-row v-if="consumeTypeState == 1">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('数字彩票参数') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('单张彩票额度')" prop="outputLottery">
                <a-input v-model="dataForm.outputLottery" oninput="value=value.replace(/\D/g,'');"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('自动出票')" prop="autoOutputLottery">
                <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.autoOutputLottery" dictCode="oc" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('自动出票延时')" prop="autoOutputLotteryDelay">
                <a-input v-model="dataForm.autoOutputLotteryDelay" oninput="value=value.replace(/\D/g,'');"></a-input>
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="12">
                    <a-form-model-item
                      style="margin-bottom: 10px"
                      :label="$t('彩票机打印缩进')"
                      prop="outputLotteryIndent"
                    >
                      <j-dict-select-tag
                        :placeholder="$t('请选择')"
                        v-model="dataForm.outputLotteryIndent"
                        dictCode="bis_game.output_lottery_indent"
                      />
                    </a-form-model-item>
                  </a-col> -->
          </a-row>
          <a-row v-if="consumeTypeState == 1">
            <div style="margin: 10px 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
              {{ $t('其它参数') }}
            </div>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('同时投退票')" prop="togetherLottery">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.togetherLottery"
                  dictCode="bis_game.together_lottery"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('投后可退次数')" prop="outputTimesWithoutInput">
                <a-input-number
                  v-model="dataForm.outputTimesWithoutInput"
                  :precision="0"
                  style="width: 40%"
                  :min="0"
                  :max="10"
                ></a-input-number>
                <span style="margin-left: 10px; color: orange">{{ $t('（0为不限制）') }}</span>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退投比率')" prop="outputInputRatio">
                <a-input-number
                  v-model="dataForm.outputInputRatio"
                  :step="1"
                  :precision="2"
                  style="width: 100%"
                  :min="0"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('专卡专投')" prop="specialInputAndCard">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.specialInputAndCard"
                  dictCode="bis_game.special_input_and_card"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('干扰检测')" prop="interferenceDetection">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.interferenceDetection"
                  dictCode="bis_game.interference_detection"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('机台类型')" prop="kind">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.kind"
                  dictCode="bis_game.kind"
                  @change="changeKind"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="dataForm.kind == 1">
              <a-form-model-item
                style="margin-bottom: 10px"
                :label="$t('缓存投币档位')"
                prop="cacheInputGear"
                :labelCol="{ span: 4 }"
                :wrapperCol="{ span: 20 }"
                required
              >
                <div>
                  <span v-for="(gear, i) in cacheInputGears" :key="i">
                    <a-input v-model="gear.value" style="width: 73px"></a-input>
                  </span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('退实票比例')" prop="outputPhysicalRatio">
                <a-input-number
                  v-model="dataForm.outputPhysicalRatio"
                  style="width: 100%"
                  :min="0.01"
                  :max="100"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item style="margin-bottom: 10px" :label="$t('无效币')" prop="invalidCoin">
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.invalidCoin"
                  dictCode="bis_game.invalid_coin"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                style="margin-bottom: 10px"
                :label="$t('会员卡认证')"
                :label-col="labelCol1"
                :wrapper-col="wrapperCol1"
                prop="cardAuth"
              >
                <j-dict-select-tag
                  :placeholder="$t('请选择')"
                  v-model="dataForm.cardAuth"
                  dictCode="bis_game.card_auth"
                  style="width: 120px"
                />
                <span style="color: orange">{{ $t('（温馨提示：设置为加强认证时刷卡可能会存在延时，请知晓！）') }}</span>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </div>
    <input-type-modal ref="typeModal" @ok="getInputTypeOk"></input-type-modal>
    <bisGameType-modal ref="modalForm" @ok="modalFormOk"></bisGameType-modal>
  </j-modal>
</template>

<script>
import moment, { min } from 'moment'
import { httpAction, getAction } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import InputTypeModal from './InputTypeModal'
import BisGameTypeModal from './BisGameTypeModal'
export default {
  name: 'GameModal',
  components: {
    InputTypeModal,
    BisGameTypeModal
  },
  data() {
    return {
      title: '',
      visible: false,
      confirmLoading: false,
      disableSubmit: false,
      dataForm: {},
      consumeTypeState: 2,
      consumeTypeDisabled: false,
      labelCol: {
        xs: { span: 20 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 20 },
        sm: { span: 16 },
      },
      labelCol1: {
        xs: { span: 10 },
        sm: { span: 4 },
      },
      wrapperCol1: {
        xs: { span: 14 },
        sm: { span: 20 },
      },
      dataSource: [],
      couponList: [],
      orderGoodsList: [],
      packageOrderList: [],
      pagination: false,
      recordsAmount: '',
      memberList: [],
      deviceList: [],
      url: {
        add: '/game/bisGame/add',
        edit: '/game/bisGame/edit',
      },
      disable: false,
      limitCycledisable: false,
      list: [],
      ticketState: true,
      coinState: false,
      columns: [
        {
          title: this.$t('门票名称'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          customCell: function (column) {
            return {
              style: {
                textAlign: 'center',
                color: '#1890ff',
                fontSize: '16px',
                height: '32px',
                lineHeight: '32px',
                fontWeight: 'bold',
                cursor: 'pointer',
              },
            }
          },
          scopedSlots: { customRender: 'action' },
        },
      ],
      piaoList: [],
      piaoValue: undefined,
      sortList: [],
      rules: {
        code: [{ required: false, message: this.$t('请输入项目编码') }],
        typeId: [{ required: true, message: this.$t('请输入项目分类') }],
        name: [{ required: true, message: this.$t('请输入项目名称') }],
        consumeType: [{ required: true, message: this.$t('请选择消费方式') }],
        inputMode: [{ required: true, message: this.$t('请选择') }],
        inputType: [{ required: true, message: this.$t('请输入投币类型') }],
        inputSpeed: [{ required: true, message: this.$t('请输入投币速度') }],
        inputPolarity: [{ required: true, message: this.$t('请输入投币极性') }],
        onceCoin1: [{ required: true, message: this.$t('请输入一局扣币') }],
        currencyPulse: [{required: true, message: this.$t('请输入实币脉冲')}],
        oncePulse: [{ required: true, message: this.$t('请输入一局脉冲') }],
        playTimes: [{ required: true, message: this.$t('请输入游戏局数') }],
        inputGear: [{ required: true, message: this.$t('请输入投币档位') }],
        inputWidth: [{ required: true, message: this.$t('请输入投币脉宽') }],
        inputInterval: [{ required: true, message: this.$t('请输入投币间隔') }],
        allowIncurrency: [{ required: true, message: this.$t('请输入投实币模式') }],
        inputByCardSoon: [{ required: true, message: this.$t('请选择刷卡即投币') }],
        checkInputLine: [{ required: true, message: this.$t('请选择检查投币线') }],
        onceAmount: [{ required: true, message: this.$t('请输入一局金额') }],
        outputSpeed: [{ required: true, message: this.$t('请输入退票速度') }],
        outputWidth: [{ required: true, message: this.$t('请输入退票脉宽') }],
        outputPolarity: [{ required: true, message: this.$t('请输入退票极性') }],
        outputType: [{ required: true, message: this.$t('请输入退票类型') }],
        outputRatio: [{ required: true, message: this.$t('请输入退票倍率') }],
        outputGoodsId: [{ required: true, message: this.$t('请输入商品') }],
        outputLottery: [{ required: true, message: this.$t('请输入单张彩票额度') }],
        autoOutputLottery: [{ required: true, message: this.$t('请选择') }],
        autoOutputLotteryDelay: [{ required: true, message: this.$t('请输入自动出票延时') }],
        outputCoin: [{ required: true, message: this.$t('请选择') }],
        togetherLottery: [{ required: true, message: this.$t('请选择') }],
        outputLotterySsrDelay: [{ required: true, message: this.$t('请输入退票时SSR延时') }],
        outputLotteryIndent: [{ required: true, message: this.$t('请选择') }],
        machineOutputLottery: [{ required: true, message: this.$t('请选择') }],
        outputLotteryKeyboardTime: [{ required: true, message: this.$t('请输入退票键输入时长') }],
        outputLotteryDelay: [{ required: true, message: this.$t('请输入退票延时') }],
        maxOutputValue: [{ required: true, message: this.$t('请输入最大退票额度') }],
        outputTimesWithoutInput: [{ required: true, message: this.$t('请输入投后可退次数') }],
        outputInputRatio: [{ required: true, message: this.$t('请输入退投比率') }],
        specialInputAndCard: [{ required: true, message: this.$t('请选择专卡专投') }],
        interferenceDetection: [{ required: true, message: this.$t('请选择') }],
        kind: [{ required: true, message: this.$t('请选择') }],
        hourCoin: [{ required: true, message: this.$t('请输入每小时扣币值') }],
        deposit: [{ required: true, message: this.$t('请输入进门押金') }],
        freeTime: [{ required: true, message: this.$t('请输入时间') }],
        minCoin: [{ required: true, message: this.$t('请输入最低消费') }],
        maxCoin: [{ required: true, message: this.$t('请输入最高消费') }],
        outputPhysicalRatio: [{ required: true, message: this.$t('请输入退实票比例') }],
        invalidCoin: [{ required: true, message: this.$t('请选择无效币') }],
        cardAuth: [{ required: true, message: this.$t('请选择') }],
      },
      addGoodsList: [],
      ruleList: [],
      inputGears: [],
      cacheInputGears: [],
      stateList: [],
      outputCoinList: [],
      priceList: [],
      memberTypeList: [],
      weeks: [
        { key: '1', name: this.$t('周一') },
        { key: '2', name: this.$t('周二') },
        { key: '3', name: this.$t('周三') },
        { key: '4', name: this.$t('周四') },
        { key: '5', name: this.$t('周五') },
        { key: '6', name: this.$t('周六') },
        { key: '7', name: this.$t('周日') },
      ],
      inputType_dictText: '',
      typeList: [],
      inputColumns: [
        {
          title: this.$t('投币类型'),
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('投币比例'),
          align: 'center',
          dataIndex: 'rate',
          customRender:(t,r)=>{
            if(r.type == '0'){
              return ''
            }
            return t+r.type_dictText+" = 1"+this.$t('币')
          }
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      inputDataSource: [],
    }
  },
  created() {
    this.initDictConfig()
  },
  mounted() {},
  methods: {
    handleAddType(){
      this.$refs.modalForm.add()
    },
    findItemById(data, id) {
      for (let item of data) {// 遍历数组中的每一项
        if (item.id === id) {// 如果当前项的 id 匹配，直接返回
          return item;
        }
        if (item.children && item.children.length > 0) {// 如果当前项有子节点，递归查找
          const found = this.findItemById(item.children, id);
          if (found) {// 如果在子节点中找到了，返回结果
            return found;
          }
        }
      }
      return null;// 如果没有找到，返回 null
    },
    handleEditType(){
      let record = this.findItemById(this.sortList,this.dataForm.typeId)
      this.$refs.modalForm.edit(record)
    },
    modalFormOk(obj){
      let that = this
      that.getSortList()
      setTimeout(function(){
        that.dataForm.typeId = obj.id
      },10)
      that.$emit('reloadType')
    },
    limitInput(input) {
      // 获取输入的值
      let value = input.value
      // 如果值大于 20000，则将其设置为 20000
      if (value > 20000) {
        input.value = 20000
      }
      // 如果值为负数，则将其设置为 0（可选）
      if (value < 0) {
        input.value = 0
      }
    },
    initDictConfig() {
      initDictOptions('bis_game.output_coin').then((res) => {
        if (res.success) {
          this.outputCoinList = res.result
        }
      })
    },
    getTypeList() {
      return new Promise((resolve) => {
        initDictOptions('bis_game.input_type').then((res) => {
          if (res.success) {
            this.typeList = res.result
          } else {
            this.typeList = []
          }
          resolve()
        })
      })
    },
    changeInputMode(e) {
      if (this.dataForm.inputMode == 0) {
        this.dataForm.inputType = 0
      } else {
        this.dataForm.inputType = ''
        this.inputType_dictText = ''
      }
    },
    addInputType() {
      this.$refs.typeModal.show({ inputList: this.inputDataSource })
    },
    getInputTypeOk(obj) {
      this.inputDataSource.push(obj)
    },
    add(state) {
      this.dataForm = {
        code: '',
        typeId: '',
        name: '',
        consumeType: '2',
        inputType: 0,
        inputMode: 0,
        inputSpeed: 5,
        inputPolarity: 1,
        oncePulse: '10',
        inputWidth: '30',
        allowIncurrency: 0,
        currencyPulse: 1,
        onceAmount: '10',
        inputInterval: 3,
        outputSpeed: 4,
        outputPolarity: 1,
        outputRatio: 1,
        outputWidth: '30',
        outputType: 2,
        checkInputLine: '1',
        inputByCardSoon: 0,
        inputGear: '10,50,100,500,1000',
        cacheInputGear: '1,2,3',
        outputLottery: 60000,
        autoOutputLottery: 1,
        autoOutputLotteryDelay: 3,
        outputCoin: 0,
        togetherLottery: 0,
        outputLotterySsrDelay: 0,
        outputLotteryIndent: 0,
        machineOutputLottery: 0,
        outputLotteryKeyboardTime: 0,
        outputLotteryDelay: 0,
        maxOutputValue: 65000,
        outputTimesWithoutInput: 0,
        outputInputRatio: 50,
        specialInputAndCard: 0,
        interferenceDetection: 0,
        kind: 0,
        hourCoin: '',
        hourTime: '15',
        cycleTime: '5',
        freeTime: '5',
        minCoin: '',
        maxCoin: '',
        outputPhysicalRatio: 1,
        deposit: '',
        invalidCoin: 0,
        playTimes: 1,
        cardAuth: '0',
      }
      this.edit(this.dataForm, state)
    },
    async edit(record, state) {
      record.outputCoin = record.outputCoin + ''
      await this.getMemberType()
      await this.getTypeList()
      let res0 = await this.getConsumeType()
      if (res0.success) {
        res0.result.forEach((rs) => {
          rs.disabled = false
        })
        this.stateList = res0.result
      }
      this.dataSource = []
      this.ruleList = []
      this.inputGears = []
      this.cacheInputGears = []
      this.inputDataSource = []
      this.consumeTypeState = record.consumeType
      if (state == 1) {
        this.consumeTypeDisabled = false
      }
      if (state == 2) {
        this.consumeTypeDisabled = true
        this.dataForm.consumeType = '1'
        this.consumeTypeState = 1
      }
      if (state == 3) {
        this.consumeTypeDisabled = false
        let x = this.stateList.findIndex((sl) => {
          return sl.value == '1'
        })
        if (x > -1) {
          this.$set(this.stateList[x], 'disabled', true)
        }
      }
      this.getSortList()
      this.visible = true
      if (!record.id) {
        this.getGoods()
        if (this.consumeTypeState == 1) {
          record.onceCoin1 = '10'
          let x = this.typeList.findIndex((t) => {
            return t.value == '0'
          })
          if(x>-1){
            this.inputDataSource=[{
              type: this.typeList[x].value,
              type_dictText: this.typeList[x].title,
              rate: 1
            }]
          }
        }
        if (this.consumeTypeState == 2) {
          record.onceCoin1 = '10'
        }
        if (this.consumeTypeState == 3) {
          record.deposit = ''
        }
        this.priceList = [
          {
            price: '',
            memberTypeId: undefined,
            weekList: [],
            weeks: ['1', '2', '3', '4', '5', '6', '7'],
            periodList: [],
            isAdd: false,
            beginTime: '',
            endTime: '',
          },
        ]
      }
      this.getGoodsList()
      if (record.allowPlay == 'Y') {
        record.allowPlays = true
      } else {
        record.allowPlays = false
      }
      if (record.consumeType == 1) {
        this.coinState = true
      } else {
        this.coinState = false
      }
      if (record.consumeType == 2) {
        this.ticketState = true
      } else {
        this.ticketState = false
      }
      if (record.id) {
        if (record.consumeType == 1 || record.consumeType == 2) {
          record.onceCoin1 = record.onceCoin
          await this.getInputType(record.id)
        }
        if (record.consumeType == 3) {
          record.deposit = record.onceCoin
        }
        if (record.consumeType == 2) {
          record.onceCoin1 = record.onceCoin
          getAction('/game/bisGame/queryBisGameTicketsByMainId', { id: record.id }).then((res) => {
            if (res.success) {
              this.dataSource = res.result
              this.dataSource.forEach((col) => {
                if (col.name == undefined) {
                  col.name = col.goodsId_dictText
                }
              })
            }
          })
          this.priceList = []
          getAction('/game/bisGamePrice/list', { gameId: record.id, pageSize: 99 }).then((res) => {
            if (res.success) {
              if (res.result.total > 0) {
                let records = res.result.records
                records.forEach((rds) => {
                  let dtl = {
                    id: rds.id,
                    gameId: rds.gameId,
                    memberTypeId: rds.memberTypeId,
                    price: rds.price,
                    weekList: rds.weekList,
                    weeks: rds.weekList.map((el) => {
                      return el.week + ''
                    }),
                    periodList: rds.periodList,
                    isAdd: false,
                  }
                  this.priceList.push(dtl)
                })
              } else {
                this.priceList = [
                  {
                    price: '',
                    memberTypeId: undefined,
                    weekList: [],
                    weeks: ['1', '2', '3', '4', '5', '6', '7'],
                    periodList: [],
                    isAdd: false,
                    beginTime: '',
                    endTime: '',
                  },
                ]
              }
            }
          })
        }
        if (record.inputMode == 1) {
          let list = record.inputType.split(','),
            arrs = []
          list.forEach((l) => {
            let dtl = this.typeList.filter((t) => {
              return t.value == l
            })[0]
            arrs.push(dtl)
          })
          this.inputType_dictText = arrs
            .map((a) => {
              return a.title
            })
            .join('->')
        }
        this.getGoods(record.outputGoodsId_dictText)
      }
      this.dataForm = Object.assign({}, record)
      this.getRule()
      if (record.inputGear) {
        let list = record.inputGear.split(',') || []
        list.forEach((lt) => {
          this.inputGears.push({
            value: lt,
          })
        })
      }
      if (record.cacheInputGear) {
        let list = record.cacheInputGear.split(',') || []
        list.forEach((lt) => {
          this.cacheInputGears.push({
            value: lt,
          })
        })
        if (list.length < 3) {
          for (var i = 0; i < 3 - list.length; i++) {
            this.cacheInputGears.push({
              value: '',
            })
          }
        }
      }
    },
    getInputType(id) {
      return new Promise((resolve) => {
        getAction('/game/bisGameInput/list', {
          gameId: id,
          pageNo: 1,
          pageSize: 20,
        }).then(res=>{
          if(res.success){
            this.inputDataSource = res.result.records
          }
          resolve()
        })
      })
    },
    getSortList() {
      let that = this
      getAction('/game/bisGameType/rootList', { pageSize: 1000 }).then((res) => {
        if (res.success) {
          let list = res.result.records
          if (list.length > 0) {
            list.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.id = '' + col.id
              col.pid = '' + col.pid
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            that.sortList = that.getDataByResult(list)
          }
        }
      })
    },
    getHasChild(store) {
      let that = this
      let query = {}
      query.pageNo = 1
      query.pageSize = 9999
      query.pid = store.id
      query.consumeType = 1
      getAction('/game/bisGameType/childList', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.pid = '' + col.pid
              col.id = '' + col.id
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            store.children = that.getDataByResult(res.result.records)
            that.sortList = [...that.sortList]
          }
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    getDataByResult(result) {
      return result.map((item) => {
        return item
      })
    },
    getConsumeType() {
      return new Promise((resolve) => {
        initDictOptions('bis_game.consume_type').then((res) => {
          resolve(res)
        })
      })
    },
    getMemberType() {
      return new Promise((resolve) => {
        getAction('/member/bisMemberRule/list', { notNonmember: 1, manageState: 'Y', pageSize: 40 }).then((res) => {
          if (res.success) {
            this.memberTypeList = res.result.records
          }
          resolve(res)
        })
      })
    },
    addPrice() {
      let dtl = {
        price: '',
        memberTypeId: undefined,
        weekList: [],
        weeks: ['1', '2', '3', '4', '5', '6', '7'],
        periodList: [],
        isAdd: false,
        beginTime: '',
        endTime: '',
      }
      this.priceList.push(dtl)
    },
    delPrice(i) {
      this.priceList.splice(i, 1)
    },
    addValidTime(i) {
      this.priceList[i].isAdd = !this.priceList[i].isAdd
    },
    delValidTime(ind, i) {
      this.priceList[i].periodList.splice(ind, 1)
    },
    focusTimeE(bol, i) {
      if (!bol && !this.priceList[i].beginTime) {
        this.$message.warn(this.$t('请选择开始时间'))
      }
    },
    orgTime(bol, i) {
      if (!bol) {
        if (!this.priceList[i].beginTime) {
          this.$message.warn(this.$t('请选择开始时间'))
          return
        }
        if (!this.priceList[i].endTime) {
          this.$message.warn(this.$t('请选择结束时间'))
          return
        }
        if (this.priceList[i].beginTime > this.priceList[i].endTime) {
          this.$message.warn(this.$t('该时间段冲突！'))
          return
        }
        this.priceList[i].isAdd = false
        this.priceList[i].periodList.push({
          beginTime: moment(this.priceList[i].beginTime).format('HH:mm'),
          endTime: moment(this.priceList[i].endTime).format('HH:mm'),
        })
      }
    },
    getRule() {
      if (this.dataForm.id) {
        getAction('/game/bisGameDiscount/list', { gameId: this.dataForm.id }).then((res) => {
          if (res.success) {
            this.ruleList = res.result.records
            if (this.ruleList.length == 0) {
              let aa = {}
              aa.coin = ''
              aa.gameNum = ''
              aa.disabled = false
              this.ruleList.push(aa)
            } else {
              this.ruleList.forEach((col) => {
                this.$set(col, 'disabled', true)
              })
            }
          }
        })
      } else {
        if (this.ruleList.length == 0) {
          let aa = {}
          aa.coin = ''
          aa.gameNum = ''
          aa.disabled = false
          this.ruleList.push(aa)
        }
      }
    },
    getGoods(value) {
      let that = this
      let querydata = {}
      querydata.pageNo = 1
      querydata.pageSize = 10
      querydata.goodsInfo = value
      querydata.form = '1'
      getAction('/goods/bisGoodsInfor/list', querydata).then((res) => {
        if (res.success) {
          that.addGoodsList = res.result.records
        }
      })
    },
    handleGoodsSearch(value) {
      this.getGoods(value)
    },
    handleChangepaytype(e) {
      this.consumeTypeState = e
      if (!this.dataForm.id) {
        if (this.consumeTypeState == 1) {
          this.dataForm.onceCoin1 = '10'
          let x = this.typeList.findIndex((t) => {
            return t.value == '0'
          })
          if(x>-1){
            this.inputDataSource=[{
              type: this.typeList[x].value,
              type_dictText: this.typeList[x].title,
              rate: 1
            }]
          }
        }
        if (this.consumeTypeState == 2) {
          this.dataForm.onceCoin1 = '10'
        }
        if (this.consumeTypeState == 3) {
          this.dataForm.onceCoin2 = ''
        }
      }
      this.ruleList = []
      this.getRule()
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleSearch(e) {
      this.getGoodsList(e)
    },
    handleChange(e) {
      this.piaoList.forEach((item) => {
        if (item.id == e) {
          let col = {}
          col.goodsId = item.id
          col.name = item.name
          col.sysOrgCode = item.sysOrgCode
          col.tenantId = item.tenantId
          this.dataSource.push(col)
        }
      })
    },
    getGoodsList(info) {
      let that = this
      that.piaoList = []
      let querydata = {}
      querydata.pageIndex = 1
      querydata.pageSize = 10
      querydata.form = '3,4'
      querydata.goodsInfo = info
      getAction('/goods/bisGoodsInfor/list', querydata).then((res) => {
        if (res.success) {
          res.result.records.forEach((col) => {
            if (col.state == 'N') {
              let index = res.result.records.indexOf(col)
              res.result.records.splice(index, 1)
            } else {
              that.piaoList.push(col)
            }
          })
        }
      })
    },
    deleteGoods(value, record, i) {
      this.dataSource.splice(i, 1)
    },
    handleOk() {
      let that = this
      that.$refs.form.validate((valid) => {
        if (valid) {
          let model = Object.assign({}, that.dataForm)
          model.bisGameDiscountList = []
          that.ruleList.forEach((col) => {
            if (col.disabled) {
              model.bisGameDiscountList.push(col)
            }
          })

          if (model.consumeType == 3 && (!model.hourTime || !model.cycleTime)) {
            that.$message.warning(that.$t('计费周期不能为空'))
            return
          }
          if (model.consumeType == 3 && Number(model.hourTime) < Number(model.cycleTime)) {
            that.$message.warning(that.$t('不能超过计费周期'))
            return
          }
          if (model.consumeType == 2) {
            model.bisGameTicketsList = that.dataSource
            model.onceCoin = model.onceCoin1
            if (model.allowPlays == true) {
              model.allowPlay = 'Y'
              if (
                model.playTimes === undefined ||
                model.playTimes === 'undefined' ||
                model.playTimes === '' ||
                model.playTimes === null ||
                model.playTimes === 'null'
              ) {
                that.$message.warning(that.$t('请输入可玩次数'))
                return
              }
            } else {
              model.allowPlay = 'N'
            }
            let arr = []
            if (that.priceList.length > 0) {
              let list = that.priceList.filter((pl) => {
                return pl.price && pl.memberTypeId
              })
              if (list.length > 0) {
                list.forEach((lt) => {
                  let dtl = {
                    price: lt.price,
                    memberTypeId: lt.memberTypeId,
                  }
                  if (lt.id) {
                    dtl.id = lt.id
                  }
                  let weeklist = []
                  if (lt.weeks.length > 0) {
                    lt.weeks.forEach((w) => {
                      let x = lt.weekList.findIndex((wl) => {
                        return wl.week == w
                      })
                      if (x > -1) {
                        weeklist.push(lt.weekList[x])
                      } else {
                        weeklist.push({ week: w })
                      }
                    })
                  }
                  dtl.weekList = weeklist
                  dtl.periodList = lt.periodList
                  arr.push(dtl)
                })
              }
            }
            model.priceList = arr
          }
          if (model.consumeType == 1) {
            if (that.inputDataSource.length == 0) {
              that.$message.warning(that.$t('至少添加一种投币类型'))
              return
            }
            model.inputList = JSON.parse(JSON.stringify(that.inputDataSource))
            model.onceCoin = model.onceCoin1
            if (model.inputByCardSoon == 0) {
              let arr = that.inputGears.filter((gear) => {
                return gear.value
              })
              if (arr.length == 0) {
                that.$message.warning(that.$t('至少输入一个投币档位值'))
                return
              }
              let len = arr.filter((a) => {
                return Number(a.value) % model.onceCoin != 0
              }).length
              if (len) {
                that.$message.warning(that.$t('投币档位位值必须为一局扣币的整数倍'))
                return
              }
              model.inputGear = arr
                .map((a) => {
                  return a.value
                })
                .join(',')
            }
          }
          if (model.consumeType == 3) {
            model.onceCoin = model.deposit
          }
          if (model.kind == 1) {
            let arr = that.cacheInputGears.filter((gear) => {
              return gear.value
            })
            if (arr.length == 0) {
              that.$message.warning(that.$t('至少输入一个缓存投币档位值'))
              return
            }
            model.cacheInputGear = arr
              .map((a) => {
                return a.value
              })
              .join(',')
          }
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!model.id) {
            httpurl += that.url.add
            method = 'post'
            model.state = 'Y'
          } else {
            httpurl += that.url.edit
            method = 'put'
          }
          httpAction(httpurl, model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                that.visible = false
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    delGear(gear, i) {
      this.inputGears.splice(i, 1)
    },
    addGear() {
      this.inputGears.push({
        value: '',
      })
    },
    changeKind(e) {
      if (e == 1 && this.cacheInputGears.length == 0) {
        this.dataForm.cacheInputGear = '1,2,3'
        let list = this.dataForm.cacheInputGear.split(',') || []
        list.forEach((lt) => {
          this.cacheInputGears.push({
            value: lt,
          })
        })
      }
    },
    handleUp(i) {
      this.inputDataSource = this.swapArrayEle(this.inputDataSource, i, i - 1)
    },
    handleDown(i) {
      this.inputDataSource = this.swapArrayEle(this.inputDataSource, i, i + 1)
    },
    handleDelete(i) {
      this.inputDataSource.splice(i, 1)
    },
    swapArrayEle(arr, i1, i2) {
      arr[i1] = arr.splice(i2, 1, arr[i1])[0]
      return arr
    },
  },
}
</script>
<style>
.cus-table1.ant-table-middle > .ant-table-content > .ant-table-body > table > .ant-table-thead > tr > th {
  padding: 6px 8px;
}
</style>